<div class="accordion-group">
	<div class="accordion-heading">
		<a class="accordion-toggle" data-toggle="collapse" data-parent="#serveradmin" href="#toolbox"> Root Toolbox </a>
	</div>
	<div id="toolbox" class="accordion-body collapse">
		<div class="accordion-inner">
			<div class="accordion" id="toolbox1">
				<select class="show-switch-drop">
					<option data-control-selector="#ssh-pass-setup">Use Password Authentication</option>
					<option data-control-selector="#ssh-auth-setup">Use Key Authentication</option>
				</select>
				<?php $SshSetupForm->id_account = $whmaccount->id_account; ?>
				<?php $form = $this->beginWidget('CActiveForm', array(
					'id' => 'ssh-pass-setup',
				)); ?>
					<?php echo $form->hiddenField($SshSetupForm, 'pass_or_key', array('value' => SshSetupForm::USE_PASS)); ?>
					<?php echo $form->hiddenField($SshSetupForm, 'id_account'); ?>
				
					<label>
						<?php echo $SshSetupForm->getFieldLabel('ssh_port'); ?>
						<?php echo $form->textField($SshSetupForm, 'ssh_port', array('class' => 'input-small')); ?>
					</label>
				
					<label>
						<?php echo $SshSetupForm->getFieldLabel('user'); ?>
						<?php echo $form->textField($SshSetupForm, 'user', array('class' => 'input-medium')); ?>
					</label>
					                                                       
					<label>
						<?php echo $SshSetupForm->getFieldLabel('pass'); ?>
						<?php echo $form->passwordField($SshSetupForm, 'pass', array('class' => 'input-medium')); ?>
					</label>
					                                                       
					<label class="checkbox">
						<?php echo $form->checkBox($SshSetupForm, 'switch_user_required', array('class' => 'show-switch-cbx', 'data-control-selector' => '.pass-su-required')) ?>
						<?php echo $SshSetupForm->getFieldLabel('switch_user_required'); ?>
					</label>
					<!-- Show only if su required is checked -->
						<label class="pass-su-required hide">
							<?php echo $SshSetupForm->getFieldLabel('su_user'); ?>
							<?php echo $form->textField($SshSetupForm, 'su_user', array('class' => 'input-medium')) ?>
						</label>
							                                                       
						<label class="pass-su-required hide">
							<?php echo $SshSetupForm->getFieldLabel('su_pass'); ?>
							<?php echo $form->passwordField($SshSetupForm, 'su_pass', array('class' => 'input-medium')) ?>
						</label>
						 
						<label class="pass-su-required hide">
							<!-- Initial Prompt:
							<input class="input-medium" type="text" value="[~]#" /> -->
							<?php echo $SshSetupForm->getFieldLabel('initial_prompt'); ?>
							<?php echo $form->textField($SshSetupForm, 'initial_prompt', array('class' => 'input-medium')) ?>
						</label>
						
						<label class="pass-su-required hide">
							<?php echo $SshSetupForm->getFieldLabel('pass_prompty'); ?>
							<?php echo $form->textField($SshSetupForm, 'pass_prompty', array('class' => 'input-medium')) ?>
						</label>
					<!-- Show only if su required is checked -->
					
					<?php echo CHtml::ajaxSubmitButton('Setup', url('whm/account/sshsetup'), array(
						'type' => 'post',
						'success' => 'js:function(ret){
							$("#ssh-pass-setup .btn").button("reset");
							afterSetup(ret);
						}',
						'beforeSend' => 'js:function(){
							//$("#ssh-pass-setup .btn").button("loading");
						}',
						'dataType' => 'json'
					), array('class' => 'btn btn-primary')); ?>
				<?php $this->endWidget(); ?>
				 
				<?php $form = $this->beginWidget('CActiveForm', array(
					'id' => 'ssh-auth-setup',
				)); ?>
					<?php echo $form->hiddenField($SshSetupForm, 'pass_or_key', array('value' => SshSetupForm::USE_KEY)); ?>
					<?php echo $form->hiddenField($SshSetupForm, 'id_account'); ?>
					
					<label>
						<?php echo $SshSetupForm->getFieldLabel('ssh_port'); ?>
						<?php echo $form->textField($SshSetupForm, 'ssh_port', array('class' => 'input-small')); ?>
					</label>
					
					<strong><?php echo $SshSetupForm->getFieldLabel('privaty_key'); ?></strong><br />
					<?php
						echo $form->textArea($SshSetupForm, 'privaty_key', array('rows' => 6, 'class' => 'span10')); 
//						echo $form->hiddenField($SshSetupForm, 'privaty_key');
					?>
					                                                       
					<!-- 
					<label class="checkbox">
						<?php //echo $form->checkbox($SshSetupForm, 'is_public_key_active_on_server'); ?>
						<?php //echo $SshSetupForm->getFieldLabel('is_public_key_active_on_server'); ?>
					</label>
					 -->
					 
					<label>
						<?php echo $SshSetupForm->getFieldLabel('user'); ?>
						<?php echo $form->textField($SshSetupForm, 'user', array('class' => 'input-medium')); ?>
					</label>
					                                                       
					<label>
						<?php echo $SshSetupForm->getFieldLabel('pass'); ?>
						<?php echo $form->passwordField($SshSetupForm, 'pass', array('class' => 'input-medium')); ?>
					</label>
					                                                       
					<label class="checkbox">
						<?php echo $form->checkBox($SshSetupForm, 'switch_user_required', array('class' => 'show-switch-cbx', 'data-control-selector' => '.authy-su-required')) ?>
						<?php echo $SshSetupForm->getFieldLabel('switch_user_required'); ?>
					</label>
					<!-- Show only if su required is checked -->
						<label class="authy-su-required hide">
							<?php echo $SshSetupForm->getFieldLabel('su_user'); ?>
							<?php echo $form->textField($SshSetupForm, 'su_user', array('class' => 'input-medium')) ?>
						</label>
							                                                       
						<label class="authy-su-required hide">
							<?php echo $SshSetupForm->getFieldLabel('su_pass'); ?>
							<?php echo $form->passwordField($SshSetupForm, 'su_pass', array('class' => 'input-medium')) ?>
						</label>
						 
						<label class="authy-su-required hide">
							<!-- Initial Prompt:
							<input class="input-medium" type="text" value="[~]#" /> -->
							<?php echo $SshSetupForm->getFieldLabel('initial_prompt'); ?>
							<?php echo $form->textField($SshSetupForm, 'initial_prompt', array('class' => 'input-medium')) ?>
						</label>
						
						<label class="authy-su-required hide">
							<?php echo $SshSetupForm->getFieldLabel('pass_prompty'); ?>
							<?php echo $form->textField($SshSetupForm, 'pass_prompty', array('class' => 'input-medium')) ?>
						</label>
					<!-- Show only if su required is checked -->
					
					<?php echo CHtml::ajaxSubmitButton('Setup', url('whm/account/sshsetup'), array(
						'type' => 'post',
						'success' => 'js:function(ret){
							$("#ssh-auth-setup .btn").button("reset");
							afterSetup(ret);
						}',
						'beforeSend' => 'js:function(){
							//$("#ssh-auth-setup .btn").button("loading");
						}',
						'dataType' => 'json'
					), array('class' => 'btn btn-primary')); ?>
				<?php $this->endWidget(); ?>
			</div>
			<div class="row-fluid">
				<div class="span12 hide" id="ssh_setup_errors">
					<div class="alert alter-block alert-warning">
						<h4>Errors</h4>
						<div class="content">
							
						</div>
					</div>
				</div>
				
				<div class="span12 hide" id="ssh_setup_success">
					<div class="alert alter-block alert-success">
						<h4>Success</h4>
						<div class="content">
							Setup success.
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<script>
	function afterSetup(ret)
	{
		if(ret.result){
			$('#ssh_setup_success').blink();
		}else{
			$("#ssh_setup_errors").blink({
				"beforeCall": function(){
					$("#ssh_setup_errors .content").html("");
					$.each(ret.errors, function(attrName, error){
						$(error).each(function(k, e){
							var p = $("<p />").addClass("text-error").append(attrName+": "+e);
							$("#ssh_setup_errors .content").append(p);
						});
					});
				}
			});
		}
	}
	$(document).ready(function(){
		$('.show-switch-cbx').click(function(){
			if($(this).is(':checked')){
				$($(this).attr('data-control-selector')).show();
			}else{
				$($(this).attr('data-control-selector')).hide();
			}
		});

		$('.show-switch-drop').change(function(){
			$.each($(this).children('option'), function(k, v){
				if($(v).is(':selected')){
					$($(v).attr('data-control-selector')).show();
				}else{
					$($(v).attr('data-control-selector')).hide();
				}
			});
		}).change();
	});
</script>